package org.road0329.tools.proto_parse_tool.enums;

/**
 * 终端透明转发操作类型
 *
 * @author zoe
 */
public enum TransitControlTypeEnum {
    /* 拉合闸 */
    POWER_STATUS(1, "通断电状态"), // 1:通断电状态
    POWER_DISCONNECT(2, "1A"), // 2:拉闸
    POWER_ALLOW_CONNECT(3, "1B"), // 3:允许合闸
    POWER_CONNECT(4, "1C"), // 4:立即合闸
    POWER_SAFETY_AUTH(5, "安全认证"), // 5:安全认证

    /* 表码实时数据 */
    FORWARD_ACTIVE_ENERGY(101, "0001FF00"),//正向有功电能
    REVERSE_ACTIVE_ENERGY(102, "0002FF00"),//反向有功电能
    FORWARD_REACTIVE_ENERGY(103, "0003FF00"),//正向无功电能
    REVERSE_REACTIVE_ENERGY(104, "0004FF00"),//反向无功电能

    /*整点冻结数据块*/
    LAST_FREEZE_DATA_BLOCK(111, "0504FF01"), //（上一次）整点冻结数据块


    /* 瞬时量实时数据 */
    U(201, "0201FF00"),//电压数据块
    I(202, "0202FF00"),//电流数据块
    P(203, "0203FF00"),//有功功率数据块
    Q(204, "0204FF00"),//无功功率数据块
    PF(205, "0206FF00"),//功率因数数据库

    /* 需量实时数据 */
    FORWARD_ACTIVE_DEMAND(301, "0101FF00"),//正向有功最大需量及发生时间
    REVERSE_ACTIVE_DEMAND(302, "0102FF00"),//反向有功最大需量及发生时间
    FORWARD_REACTIVE_DEMAND(303, "0103FF00"),//正向无功最大需量及发生时间
    REVERSE_REACTIVE_DEMAND(304, "0104FF00"),//反向无功最大需量及发生时间

    /* 电信iot切换接入地址 645-07扩展*/
    SERVER_IP_PORT(401, "99991201"),//服务器IP端口
    MODULE_VERSION(402, "04800004"),//模块软件版本号

    /* 电信iot切换接入地址 188扩展*/
    READ_IP_PORT_CONNECT_MODE(411, "831C"),//服务器IP端口与连接方式
    WRITE_IP_PORT_CONNECT_MODE(412, "A31C"),//服务器IP端口与连接方式
    SLEEP_NOW(413, "A31E"),//立即休眠

    /* NB 电表 上报停电事件 645-07扩展*/
    POWER_CUT_EVENT(421, "03110001"),//停电事件

    /*纳宇专属*/
    NAYU_REAL_DATA(1001, "实时数据"),

    /*本地电费控esam*/
//    ESAM_WALLET_INIT(5001, "钱包初始化"), //卡表钱包初始化(需要在测试秘钥下初始化，暂时不支持远程初始化)
    ESAM_OPEN_ACCOUNT(5002, "开户"), //卡表开户
    ESAM_BUY_POWER(5003, "购电"), //卡表购电
    //    ESAM_REFUND(5004, "退款"), //卡表钱包退费(暂不支持远程退款)
    ESAM_QUERY_STATUS(5011, "状态查询"), //状态查询
    ESAM_DATA_RECALL(5012, "数据回抄"), //数据回抄;
    /*国网esam第一类数据*/
//    ESAM_PRICE_SET(5021, "备用电价下发"),//备用电价设置
    ESAM_TARIFF_PRICE(5021, "备用套费率电价"), //备用套费率电价
    ESAM_TARIFF_PRICE_DATE(5022, "主备费率切换时间"), //主备费率切换时间
    ESAM_LADDER_PRICE(5023, "备用套阶梯电价"), //备用套阶梯电价
    ESAM_LADDER_PRICE_DATE(5024, "主备阶梯切换时间"), //主备阶梯切换时间
    ESAM_ALARM_MONEY1_LIMIT(5031, "报警金额1限值"), //报警金额1限值
    ESAM_ALARM_MONEY2_LIMIT(5032, "报警金额2限值"), //报警金额2限值
    ESAM_OVERDRAW_MONEY_LIMIT(5033, "透支金额限值"), //透支金额限值
    ESAM_HOARD_MONEY_LIMIT(5034, "囤积金额限值"), //囤积金额限值
    ESAM_CONNECT_MONEY_LIMIT(5035, "合闸允许金额限值"), //合闸允许金额限值
    ESAM_TOTAL_BUY_MONEY_LAST_1(5041, "上1次购电后累计购电金额"), //上1次购电后累计购电金额

    ;

    private final int key;
    private final String value;

    TransitControlTypeEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public int getKey() {
        return key;
    }

    public Short getShortValue() {
        Integer obj = key;
        return obj.shortValue();
    }

    /**
     * 通过传入的字符串匹配枚举，传入值
     *
     * @param key
     * @return
     */
    public static TransitControlTypeEnum getEnmuByKey(int key) {
        for (TransitControlTypeEnum at : TransitControlTypeEnum.values()) {
            if (at.getKey() == key) {
                return at;
            }
        }
        return null;
    }

    /**
     * 通过传入的字符串匹配枚举获得描述，传入值
     *
     * @param key
     * @return
     */
    public static String getValue(int key) {
        TransitControlTypeEnum type = getEnmuByKey(key);
        return type == null ? "" : type.value;
    }

    /**
     * 通过传入的字符串匹配枚举，传入值
     *
     * @param value
     * @return
     */
    public static TransitControlTypeEnum getEnmuByValue(String value) {
        for (TransitControlTypeEnum at : TransitControlTypeEnum.values()) {
            if (at.getValue().equalsIgnoreCase(value)) {
                return at;
            }
        }
        return null;
    }

}
